"use strict";
const common_vendor = require("../../common/vendor.js");
const common_request = require("../../common/request.js");
const _sfc_main = {
  onShareAppMessage() {
    return {
      title: this.currentLabel,
      // Change the title to the current item.label value
      imageUrl: ""
      // path: ""
    };
  },
  data() {
    return {
      tabs: [
        { value: "厨下", label: "厨下" },
        { value: "净饮", label: "净饮" },
        { value: "全屋", label: "全屋" },
        { value: "空净", label: "空净" },
        { value: "套餐", label: "套餐" }
      ],
      code: "",
      label: "",
      allTabsData: [],
      dynamicColor: "",
      currentTabsData: {}
    };
  },
  onLoad(options) {
    const { label, code } = options;
    if (label && code) {
      this.currentLabel = label;
      this.code = label;
    }
    label && common_vendor.index.setNavigationBarTitle({ title: label });
    this.getProducts();
  },
  methods: {
    getCategories() {
      common_request.service({
        url: "/index/xy_category",
        method: "get"
      }).then((res) => {
        if (res && res.length) {
          this.getProducts(res[0].id);
        }
      });
    },
    onImageError(product) {
      this.$set(product, "error", true);
    },
    getCurrentTabsData(value) {
      return this.allTabsData.find((e) => e.name === value);
    },
    getProducts(id) {
      common_request.service({
        url: "/category/index"
      }).then((res) => {
        if (!res)
          return;
        res = res.data;
        this.tabs = res.map((e) => {
          return {
            label: e.name,
            value: e.name
          };
        });
        this.allTabsData = res.map((e) => {
          return {
            ...e,
            titles: (e.titles || []).map((title) => {
              return {
                ...title,
                products: (title.products || []).map((prod) => {
                  return {
                    ...prod,
                    icon: Array.isArray(prod.icon) ? prod.icon[0] : prod.icon
                  };
                })
              };
            })
          };
        });
        const value = (this.tabs.find((e) => e.value === this.currentLabel) || {}).value || this.tabs[0].value;
        this.currentTabsData = this.getCurrentTabsData(value);
      });
    },
    setCurrentCode(item) {
      this.code = item.value;
      this.label = item.label;
      common_vendor.index.setNavigationBarTitle({ title: item.label });
      this.currentTabsData = this.getCurrentTabsData(item.value);
    },
    goToGoodsDetail(id) {
      common_vendor.index.navigateTo({
        url: `/pages/goods-detail/goods-detail?id=${id}`
      });
    },
    getHtml(str) {
      if (!str)
        return "";
      let domain = "https://fullhouse.qinyuan.cn";
      let newHtmlStr = str.replace(/src="\/uploads/g, `src="${domain}/uploads`);
      var newContent = newHtmlStr.replace(/<img[^>]*>/gi, (match) => {
        let processed = null;
        if (!match.match(/style=\"(.*)\"/gi)) {
          processed = match.replace(/\<img/g, '<img style="width:100%;height:auto;display:block"');
        } else {
          processed = match.replace(/style=\"(.*)\"/gi, 'style="width:100%;height:auto;display:block"');
        }
        return processed;
      });
      return newContent;
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.f($data.tabs, (item, index, i0) => {
      return {
        a: common_vendor.t(item.label),
        b: item.value === $data.code ? 1 : "",
        c: index,
        d: common_vendor.o(($event) => $options.setCurrentCode(item), index)
      };
    }),
    b: $data.currentTabsData && $data.currentTabsData.titles
  }, $data.currentTabsData && $data.currentTabsData.titles ? {
    c: "https://fullhouse.qinyuan.cn/" + $data.currentTabsData.image_src,
    d: common_vendor.f($data.currentTabsData.titles, (item, index, i0) => {
      return {
        a: $options.getHtml(item.title_name),
        b: common_vendor.f(item.products, (product, subIndex, i1) => {
          return common_vendor.e({
            a: product.error
          }, product.error ? {} : {
            b: common_vendor.o(($event) => $options.onImageError(product), subIndex),
            c: "https://fullhouse.qinyuan.cn/" + product.icon
          }, {
            d: common_vendor.t(product.name),
            e: subIndex,
            f: common_vendor.o(($event) => $options.goToGoodsDetail(product.id), subIndex)
          });
        }),
        c: index
      };
    }),
    e: $data.dynamicColor,
    f: $data.code
  } : {}, {
    g: $data.code
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:/Users/karo/Desktop/finale/3.0/clean-water/clean-water/pages/tabbar/tabbar.vue"]]);
_sfc_main.__runtimeHooks = 2;
wx.createPage(MiniProgramPage);
